/**
 * 
 */
package DBPedia;

import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.MatchResult;

/**
 * @author van Sambeek
 *
 */
public class DBPNTParser {
	List<String> DBPNTElementList;
	
	public DBPNTParser(){
		DBPNTElementList = new ArrayList<String>();
		parseDocument();
	}
	
	private void parseDocument() {

		// get a scanner
		Scanner sc = null;
		try {
			sc = new Scanner(new File("labels_nl.nt"));	
			int j = 0;

			while(sc.hasNextLine() && j <15000){
				//String next = 
				//System.out.println(next);
				sc.findInLine("<http://dbpedia.org/resource/(.*)> <http://www.w3.org/2000/01/rdf-schema#label> \"(.*)\"@nl .");
				
				MatchResult result = sc.match();
				for (int i=1; i<=result.groupCount(); i++){
					//String string = "abc\u5639\u563b\u00EBAustrali\u00EB";
					String string = (String) result.group(i);
					//byte[] utf8 = string.getBytes("UTF-8");
					//String string2 = new String(utf8, "UTF-8");
					string = string.replace("\\u00EB", "ë");
					string = string.replace("\\u00E1", "á");
					string = string.replace("\\u00EF", "ï");
					string = string.replace("\\u00E8", "è");
					string = string.replace("\\u00F6", "ö");
					string = string.replace("\\u00D6", "Ö");
					string = string.replace("\\u00E7", "ç");
					string = string.replace("\\u00FC", "ü");
					string = string.replace("\\u00DC", "Ü");
					string = string.replace("\\u00C9", "É");
					string = string.replace("\\u00E9", "é");
					string = string.replace("\\u266F", "#");
					string = string.replace("\\u00E4", "ä");
					string = string.replace("\\u0026", "&");
					string = string.replace("\\u003C", ">");
					string = string.replace("\\u003E", "<");
					string = string.replace("\\u00C4", "Ä");
					string = string.replace("\\u015F", "ş");
					string = string.replace("\\u0161", "š");
					string = string.replace("\\u00ED", "í");
					string = string.replace("\\u0142", "ł");
					string = string.replace("\\u0141", "Ł");
					string = string.replace("\\u00F3", "ó");
					string = string.replace("\\u017A", "ź");
					string = string.replace("\\u00EE", "î");
					string = string.replace("\\u00C5", "Å");
					string = string.replace("\\u00F1", "ñ");
					string = string.replace("\\u0117", "ė");
					string = string.replace("\\u00E3", "ã");
					string = string.replace("\\u00EA", "ê");
					string = string.replace("\\u017E", "ž");
					string = string.replace("\\u00F4", "ô");
					string = string.replace("\\u0144", "ń");
					string = string.replace("\\u010D", "č");
					
					string = string.replace("\\u0103", "ă");
					string = string.replace("\\u0107", "ć");
					string = string.replace("\\u00F9", "ù");
					string = string.replace("\\u00F8", "ø");
					string = string.replace("\\u00E0", "à");
					string = string.replace("\\u015A", "Ś");
					
					string = string.replace("\\u015B", "ś");
					string = string.replace("\\u00C1", "Á");
					string = string.replace("\\u010C", "Č");
					string = string.replace("\\u015A", "Ś");
					string = string.replace("\\u015A", "Ś");
					string = string.replace("\\u015A", "Ś");
					string = string.replace("\\u015A", "Ś");
					
					/*byte[] utf8 = string.getBytes("UTF-8");
					string = new String(utf8,"UTF-8");*/
					
					
					
					
					string = URLDecoder.decode(string,"UTF-8");
					System.out.println(string);
					DBPNTElementList.add(string);
				}
				
				j++;
				sc.nextLine();
			}		
			
			sc.close();
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public List<String> getDBPNTElementList(){
		return DBPNTElementList;
	}
	
	public static void main(String[] args) {
		DBPNTParser spe = new DBPNTParser();
		//spe.parseDocument();
	}
}
